#ifndef TRAJECTORYCAPTURE_H
#define TRAJECTORYCAPTURE_H

#include <QObject>
#include <QImage>

#include <cv.h>
#include <mlgesture.h>
#include <gestureobserver.h>
#include <string>

class TrajectoryCapture : public QObject, public mlgesture::GestureObserver {
	Q_OBJECT
public:
	TrajectoryCapture(vector<mlgesture::Trajectory>* trajectories);
	TrajectoryCapture(int cam_id, vector<mlgesture::Trajectory>* trajectories);
	~TrajectoryCapture();
	void setParams(int cam_id=-1, int low_skin=-1, int upper_skin=-1, int low_value = -1, int upper_value = -1,
				   bool adapt_algorithm = true, double trackin_sensity_ = -1);
	const QImage& getFrame() const;
	const QImage& getMask() const;
	const QImage& getTrajectory() const;
	const QImage& getDirection() const;
	vector<mlgesture::Trajectory>* getTracks();
	bool getTrackingState() const;
	void saveShape(const QString path) const;
	void processEvent(mlgesture::GestureEvent *event);

public slots:
	void frameProcess();
	void trajectoryProcess();
	void render();
	void stopTracking();
	void activateTracking();

private:
	cv::Mat frame_;
	cv::Mat mask_;
	cv::Mat track_;
	cv::Mat direction_;
	QImage frameImg_;
	QImage maskImg_;
	QImage trackImg_;
	QImage directionImg_;
	cv::Point lastPos_;
	cv::Point lastDirPos_;
	bool gestureState_;
	bool trackingState_;
	bool cameraState_;
	mlgesture::MLGesture *gesture_;
	vector<mlgesture::Trajectory>* tracks_;
	mlgesture::Trajectory actTrack_;
	bool isError_;
	QString errorMessage_;
};

#endif // TRAJECTORYCAPTURE_H
